<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>续保提醒</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">保单到期日</div>
                    <div class="field">
                        <input ligerui="width:82" name="plcEndTmMin" id="plcEndTmMin" type="text" class="ui-datepicker" value="">-
                        <input ligerui="width:82" name="plcEndTmMax" id="plcEndTmMax" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="contNo" id="contNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">续保状态</div>
                    <div class="field">
                        <input name="reneStsCd" id="reneStsCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null,detailGrid=null,callback=null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insRenwal/initList.do',
            method: 'get',
            columns: [
                {display:'客户',name:'cstNm',minWidth: 100, align: 'left'},
                {display:'合同号',name:'contNo',minWidth: 100, align: 'left'},
                {display:'客户经理',name:'cstMgrNm',minWidth: 100, align: 'left'},
                {display:'省公司',name:'cstMgrOrgCdNm',minWidth: 100, align: 'left'},
                {display:'提醒保单数',name:'prdQty',width: 100, align: 'right'},
                {display:'保单到期日',name:'plcEndTm',width: 100, align: 'left',render:renderDate},
                {display:'操作',name:'',width:100,align:'center',
                    render:function(rowdata,rowindex,value){
                        return '<a style="cursor: pointer;" onclick="qyCommRec('+rowdata.cstId+',\''+rowdata.cstNm+'\',\''+rowdata.contNo+'\');">提醒记录</a>';
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function ()
            {
                var grid = this;
                grid.collapsedRows = [];
            },
            detail: {
                height: 'auto',
                onShowDetail: showDetail_grid
            }

        });
        grid.setHeight(100);

        $("#reneStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });
        $("#searchBar").ligerForm();
        liger.get("reneStsCd").setData(${reneStsCdList});

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            Add_navTab("InsPlcBscInfo_1", "新增保单", '<%=path%>/insurance/insPlcBscInfo/toAddPage.do', callback);
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            Add_navTab('InsPlcBscInfo_2'+_id, "修改保单", '<%=path%>/insurance/insPlcBscInfo/toModifyPage.do?id='+_id, callback);
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/insurance/insPlcBscInfo/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

    });

    //保单产品详情
    function showDetail_grid(row, detailPanel, callback){
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);

        var form = liger.get("searchBar");
        var data = form.getData();
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/insurance/insRenwal/initPrdList.do?prjId='+row.prjId,
            method: 'post',
            parms:data,
            columns: [
                {display: '支付表号', name: 'paySchNo', width: 160, align: 'left',
                    render:function(rowdata,rowindex,value){
                        return '<a href="javascript:;" onclick="showPrjPrdPaySchDtl('+rowindex+')"><span class="gridTip" title="支付表查看">'+rowdata.paySchNo+'</span></a>';
                    }
                },
                {display: '资产状态', name: 'prdStsCdNm', minWidth: 100, align: 'left'},
                {display: '联系人', name: 'cstNm', minWidth: 150, align: 'left'},
                {display: '联系电话', name: 'lkPhone', minWidth: 100, align: 'left'},
                {display: '产品名称', name: 'prdNm', minWidth: 100, align: 'left'},
                {display: '产品型号', name: 'prdMdl', minWidth: 100, align: 'center'},
                {display: '保单到期时间', name: 'plcEndTm', minWidth: 100, align: 'center',render:renderDate},
                {display: '保单号', name: 'plcNo', minWidth: 100, align: 'center',
                    render:function(rowdata,rowindex,value){
                        if(!value||value==null||value=='null'){
                            return '<a href="javascript:;" onclick="queryPlcDtl('+rowdata.id+')">保单</a>';
                        }
                        return '<a href="javascript:;" onclick="queryPlcDtl('+rowdata.id+')"><span class="gridTip" title="保单查看">'+rowdata.plcNo+'</span></a>';
                    }
                },
                {display: '保险种类', name: 'insTypCdNm', minWidth: 100, align: 'center'},
                {display: '续保状态', name: 'reneStsCdNm', minWidth: 100, align: 'center'},
                {display: '流程编号', name: 'prInstNo', minWidth: 100, align: 'center',
                    render: function (rowdata, rowindex, value, column) {
                        if (value&&rowdata.audStsCd!="3") {
                            return '<a href="javascript:commShowFlow(\'' + rowdata.prInstId + '\',' + rowdata.audStsCd + ',' + rowdata.renewId+ ');">' + value + '</a>';
                        } else {
                            return '<a href="javascript:addPlc(' + rowdata.id + ',' +rowdata.renewId+ ',' + rowdata.prjPrdDtlId + ');">发起申请</a>';
                        }
                    }
                },
            ],
            root: 'rows',
            hideLoadButton : true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers:true,  //显示序号
            checkbox: true,
            allowUnSelectRow:true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    //查询提醒记录
    function qyCommRec(_cstId,_cstNm,_contno){
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 1110,
            height: 500,
            title: '提醒记录',
            url:'<%=path%>/risk/rskCommRec/toListPage.do?cstId='+_cstId+'&cstNm='+_cstNm+'&bizNo='+_contno+'&qt=1&buTypCd=3',
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    // 支付表详情
    function showPrjPrdPaySchDtl(rowindex){
        var editFlag = true;
        var rowdata = detailGrid.getRow(rowindex);
        var prjId = rowdata.prjId;
        var id = rowdata.paySchId;
        var prjPrdDtlId = rowdata.prjPrdDtlId;
        var prjPrdId = rowdata.prjPrdId;
        Add_navTab('tab_prj_quat_prps'+id,'查看支付表','<%=path%>/project/prjprdpayschm/toAddPage.do?prjId='+prjId+'&&id='+id+'&&prjPrdDtlId='+prjPrdDtlId+'&&prjPrdId='+prjPrdId+'&&detailFlag='+editFlag);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //查询保单详情
    function queryPlcDtl(_id){
        Add_navTab('InsPlcBscInfo_DTL_'+_id, "保单详情", '<%=path%>/insurance/insPlcBscInfo/toDetailPage.do?id='+_id, null);
    }

    //显示流程
    function commShowFlow(_pInstId,_audStsCd,_businessKey){
        if(StringUtils.isEmpty(_pInstId)){
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/insurance/insPlcBscInfo/toCheckPage.do?id=";
    	var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_businessKey+"&formUrl="+_formUrl;
        Add_navTab('tab_cst_invoice_flow_'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
    }

    //续保申请
    function addPlc(plcId,renewId,prjPrdDtlId) {
        if(!renewId || renewId=='null'){
            renewId='';
        }
        Add_navTab("PlcRenew_"+prjPrdDtlId, "新增续保保单", '<%=path%>/insurance/insPlcBscInfo/toAddRenewPage.do?renewId='+renewId+'&plcId='+plcId+'&prjPrdDtlId='+prjPrdDtlId+'&flag=1', callback);
    }

</script>

</body>
</html>
